#ifndef GETOPT_HPP
#define GETOPT_HPP

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif

#include <vector>
#include <map>
#include <string>

struct LongOpt{
    LongOpt(const char *name_,int has_arg_,int val_):name(name_),has_arg(has_arg_),val(val_){}
    LongOpt(const std::string &name_,int arg,int v):name(name_),has_arg(arg),val(v){}
    LongOpt(const struct option &opt):name(opt.name),has_arg(opt.has_arg),val(opt.val){}
    std::string name;
    int has_arg;
    int val;
};

class getoptions{
public:
    getoptions(int argc, char **argv,struct option *longopts);
    virtual ~getoptions();
    const std::map<std::string,std::string> argument()const{
        return mArgument;
    }
    const std::vector<std::string> nonoption_argument()const{
        return mNonoptArgument;
    }
    int error()const{
        return mError;
    }
protected:
    virtual int option(int ch, const char *arg, int optch);
    virtual int non_option(const char *arg);
private:
    std::map<std::string,std::string> mArgument;
    std::map<int,LongOpt> mOptions;
    std::vector<std::string> mNonoptArgument;
    int mError;
};

#endif // GETOPT_HPP
